﻿@using DevExpress.Web.Mvc
@using DevExpress.Web.Mvc.UI

@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "ProductID";
            settings.CallbackRouteValues = new { Controller = "Editing", Action = "EditModesPartial" };
            settings.CustomActionRouteValues = new { Controller = "Editing", Action = "ChangeEditModePartial" };
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Editing", Action = "EditModesAddNewPartial" };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Editing", Action = "EditModesUpdatePartial" };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Editing", Action = "EditModesDeletePartial" };
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.CommandColumn.Visible = true;
            //settings.com

            settings.Columns.Add("ProductName");
            settings.Columns.Add(column => {
                column.FieldName = "CategoryID";
                column.Caption = "Category";
                column.ColumnType = MVCxGridViewColumnType.ComboBox;
                
            });
            settings.Columns.Add("QuantityPerUnit");
            settings.Columns.Add(column => {
                column.FieldName = "UnitPrice";
                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                
            });
            settings.Columns.Add(column => {
                column.FieldName = "UnitsInStock";
                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            });
            settings.Columns.Add("Discontinued", MVCxGridViewColumnType.CheckBox);

            settings.PreRender = (sender, e) => {
                ((MVCxGridView)sender).StartEdit(1);
            };
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()